package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/9 18:37
 */
@Service
public class UserServiceImpl implements  UserService{

    @Autowired
     private UserMapper userMapper;

    @Override
    public List<User> findUserAll() {
        List<User> list = userMapper.selectList(null);

        return list;
    }

    @Override
    public List<User> findByNameAndSexAndBirthday() {
        /**
         * 创建查询条件构造器
         */
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();

        //2.查询根据姓名模糊查询条件
        userQueryWrapper.like("name", "王");
        //设置根据性别查询
        userQueryWrapper.eq("sex", "男");
        //4.设置根据日期查询条件范围
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date parse = sdf.parse("2021-02-01 00:00:00");
            userQueryWrapper.ge("birthday",parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        List<User> list = userMapper.selectList(userQueryWrapper);
        return list;
    }

    @Override
    public int addUser(User user) {
        int update = userMapper.update(user, null);
        return update;
    }


}
